package cn.worldyao.demo.entity;

import cn.worldyao.demo.config.LocalDateTimeConfig;
import cn.worldyao.demo.util.Tools;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableField;
import java.io.Serializable;
import java.time.LocalDateTime;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
 * <p>
 *
 * </p>
 *
 * @author yaozi
 * @since 2020-03-11
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class SysUser extends Model<SysUser> {

    private static final long serialVersionUID = 1L;

    @TableId(value = "UID", type = IdType.INPUT)
    private String uid;

    @TableField("USERNAME")
    private String username;

    @TableField("PASSWORD")
    private String password;

    @TableField("SALT")
    private String salt;

    @TableField("ROLE_PATH")
    private String rolePath;

    @TableField("CREATE_TIME")
    @JsonDeserialize(using = LocalDateTimeConfig.class)
    private LocalDateTime createTime;

    @TableField("UPDATE_TIME")
    @JsonDeserialize(using = LocalDateTimeConfig.class)
    private LocalDateTime updateTime;


    @Override
    protected Serializable pkVal() {
        return this.uid;
    }

    public void Init() {
        this.setUid(Tools.UUID8());
        this.setSalt(Tools.Salt8());
        this.setCreateTime(LocalDateTime.now());
        this.setUpdateTime(LocalDateTime.now());
        this.setPassword(Tools.MD5Pwd(this));
    }

    @Override
    public String toString() {
        return "User{" +
                "uid=" + uid +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", salt=" + salt + '\'' +
                ", create_time=" + createTime + '\'' +
                ", update_time=" + updateTime +
                '}';
    }

}
